package cn.stylefeng.guns.modular.fruits.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.fruits.entity.FruitsStorageStock;
import cn.stylefeng.guns.modular.fruits.mapper.FruitsStorageStockMapper;
import cn.stylefeng.guns.modular.fruits.model.params.FruitsStorageStockParam;
import cn.stylefeng.guns.modular.fruits.model.result.FruitsStorageStockResult;
import  cn.stylefeng.guns.modular.fruits.service.FruitsStorageStockService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 库存管理 服务实现类
 */
@Service
public class FruitsStorageStockServiceImpl extends ServiceImpl<FruitsStorageStockMapper, FruitsStorageStock> implements FruitsStorageStockService {

    @Override
    public void add(FruitsStorageStockParam param){
        FruitsStorageStock entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(FruitsStorageStockParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(FruitsStorageStockParam param){
        FruitsStorageStock oldEntity = getOldEntity(param);
        FruitsStorageStock newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public FruitsStorageStockResult findBySpec(FruitsStorageStockParam param,Long operateId){
        return this.baseMapper.findBySpec(param, operateId);
    }

    @Override
    public List<FruitsStorageStockResult> findListBySpec(FruitsStorageStockParam param,Long operateId){
        return this.baseMapper.findListBySpec(param, operateId);
    }

    @Override
    public LayuiPageInfo findPageBySpec(FruitsStorageStockParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(FruitsStorageStockParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private FruitsStorageStock getOldEntity(FruitsStorageStockParam param) {
        return this.getById(getKey(param));
    }

    private FruitsStorageStock getEntity(FruitsStorageStockParam param) {
        FruitsStorageStock entity = new FruitsStorageStock();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public List<FruitsStorageStockResult> findStorageStockSumBySpec(FruitsStorageStockParam param,Long operateId) {
		return this.baseMapper.findStorageStockSumBySpec(param, operateId);
	}

	@Override
	public List<FruitsStorageStockResult> findStorageStockSumBySpec2(FruitsStorageStockParam param,Long operateId) {
		return this.baseMapper.findStorageStockSumBySpec2(param, operateId);
	}

	@Override
	public List<FruitsStorageStockResult> findStorageStockSumBySpec3(FruitsStorageStockParam param,Long operateId) {
		return this.baseMapper.findStorageStockSumBySpec3(param, operateId);
	}

	@Override
	public List<FruitsStorageStockResult> findStorageStockSumBySpec4(FruitsStorageStockParam param,Long operateId) {
		return this.baseMapper.findStorageStockSumBySpec4(param, operateId);
	}

	@Override
	public List<FruitsStorageStockResult> findStorageStockSum(FruitsStorageStockParam param) {
		return this.baseMapper.findStorageStockSum(param);
	}

	@Override
	public FruitsStorageStockResult findBySpecGt(FruitsStorageStockParam param,Long operateId) {
        return this.baseMapper.findBySpecGt(param, operateId);
	}

	@Override
	public FruitsStorageStockResult findBySpecByPositionNumber(FruitsStorageStockParam param,Long operateId) {
		return this.baseMapper.findBySpecByPositionNumber(param, operateId);
	}

	@Override
	public List<FruitsStorageStockResult> findListBySpecAndPositionNumber(FruitsStorageStockParam param,Long operateId) {
		return this.baseMapper.findListBySpecAndPositionNumber(param, operateId);
	}

}
